import {
	findNodeHandle, UIManager
} from "react-native";
import HTTP from '../../../../utils/http';
import { API, API_GENERATE } from '../../../../config/api';

/*
  获取审批列表
  approveType  订单->O  付款申请->P  授信—>C  合同变更->A
*/
class OrderApproveService {

	//审批列表
	getApproveList(params, tabIndex, sendData = {}) {
		//订单审批
		if (params.approveType === 'O') {
			return HTTP.POST(API_GENERATE(API.ORDER_LOT), sendData);
		}
		//付款申请参数比较特殊，需要多传formKey
		if (params.approveType === 'P') {
			// Object.assign(sendData, JSON.parse(params.formKey));
			return HTTP.POST(API_GENERATE(API.MUL_PAY_APPROVEL), sendData);
		}
		//授信
		if (params.approveType === 'C') {
			return HTTP.POST(API_GENERATE(API.MUL_CREDIT_AUDIT_APPROVEL), sendData);
		}
		//合同变更
		if (params.approveType === 'A') {
			return HTTP.POST(API_GENERATE(API.MUL_ORDER_CHANGE_AUDIT), sendData);// 合同
		}
		//框架变更
		if (params.approveType === 'LC') {
			return HTTP.POST(API_GENERATE(API.ORDER_LONG_APPROVE), sendData);// 合同
		}
		//泉化销售
		if (params.approveType === 'QH') {
			return HTTP.POST(API_GENERATE(API.MUL_QH_ORDER_LOT), sendData);
		}
		//中新油变更
		if (params.approveType === 'ZXYC') {
			return HTTP.POST(API_GENERATE(API.GET_NEW_OIL_ORDER_CHANGE), sendData);
		}
	}

	getApproveDetail(params, sendData = {}) {
		//付款审批详情
		if (params.approveType === 'P') {
			return HTTP.POST(API_GENERATE(API.PAY_APPROVEL_DETAIL), sendData);
		}
		//订单审批详情
		if (params.approveType === 'O' || params.approveType === 'QH') {
			return HTTP.POST(API_GENERATE(API.ORDER_DETAIL), sendData);
		}
	}

	goApprove(params, sendData = {}) {
		//付款审批
		if (params.approveType === 'P') {
			return HTTP.POST(API_GENERATE(API.PAY_APPLY_APPROVEL), sendData);
		}
		//订单审批
		if (params.approveType === 'O') {
			return HTTP.POST(API_GENERATE(API.ORDER_TASTK_APPROVAL), sendData);
		}
		//泉化销售审批
		if (params.approveType === 'QH') {
			return HTTP.POST(API_GENERATE(API.QH_ORDER_TASTK_APPROVAL), sendData);
		}
	}

	//获取审批节点
	getApproveState(params, sendData = {}) {
		if (params.approveType === 'P') {
			Object.assign(sendData, { bizObjType: 13 })
		}
		if (params.approveType === 'O') {
			Object.assign(sendData, { bizObjType: 1 })
		}
		if (params.approveType === 'QH') {
			Object.assign(sendData, { bizObjType: 17 })
		}
		return HTTP.GET(API_GENERATE(API.APPROVAL_NODE), sendData);
	}

	//获取意向客户信息
	getPotentialClient(sendData = {}) {
		return HTTP.POST(API_GENERATE(API.POTENTIAL_CLIENTS_LIST), sendData);
	}

	//获取盈利数据
	getProfitData(sendData = {}) {
		return HTTP.POST(API_GENERATE(API.GET_PROFITANALYSE), sendData);
	}

	//图片预览
	preview(sendData = {}) {
		return HTTP.GET(API_GENERATE(API.GET_IMG_VIEW), sendData, null, 30000);
	}

	//根据付款类型返回对应发货期限的说明
	setPayTypeName(payType) {
		if ('3' === payType) {
			return '货到';
		}
		else if ('4' === payType) {
			return '签订';
		}
		else if ('5' === payType) {
			return '票到';
		} else {
			return '签订';
		}
	}

	//获取组件的宽高等
	layout(ref) {
		const handle = findNodeHandle(ref);
		return new Promise((resolve) => {
			UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
				resolve({
					x,
					y,
					width,
					height,
					pageX,
					pageY
				});
			});
		});
	}


	TASK_KEY = {
		'ApprovalDefaultPage': 'L',  //领导等其他角色
		'BackToBackSalePage': 'B',  //背靠背
		'FinanceApprovelPage': 'F',  //财务类
		'RiskManagerApprovelPage': 'R',  //风控类
	}
}

module.exports = new OrderApproveService();
